/*
 * BitUtils.h
 *
 *  Created on: Dec 3, 2011
 *      Author: shaohong
 */

#ifndef BITUTILS_H_
#define BITUTILS_H_

#include <stdint.h>

namespace nmps {


typedef struct {
	unsigned char bytes[4];
} Quartet;


class BitUtils {
public:
	BitUtils();
	virtual ~BitUtils();

	/**
	 * Get the bit value in the position of the given number.
	 * The counting starts from the right with the rightmost bit @ position 0.
	 */
	static unsigned char getBitValue(uint32_t value, int position);

	/**
	 * for the given byte (byte), set the given bit (bitIndex) to the given value (bitValue)
	 * The index is count from the right and the rightmost pos is index 0
	 */
	static void setBitValue(unsigned char* byte, unsigned bitIndex, unsigned char bitValue);

	/**
	 * set the value to the quartet. at the bits starting at starPos and using nBits.
	 * the position counting starts from left to right and the left most bit is position 0
	 */
	static void setRtpHeaderValue(Quartet* quartet, int startPos, int nBits, uint32_t value);

};

} /* namespace nmps */
#endif /* BITUTILS_H_ */
